package com.example.demo.controller;

import com.example.demo.model.Drink;
import com.example.demo.model.Student;
import com.example.demo.service.IDrinkService;
import org.joda.money.CurrencyUnit;
import org.joda.money.Money;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class RouterController {
    @Autowired
    public IDrinkService iDrinkService;
    // 后台登录页面路由
    @GetMapping("/")
    public String Index(){
        return "manage/login";
    }
    // 后台首页路由
    @GetMapping("/manage/index")
    public String adminIndex(){
        return "manage/index";
    }
    // 后台欢迎页面路由
    @GetMapping("/manage/welcome")
    public String adminWelcome(){
        return "manage/welcome";
    }

    @GetMapping("/menu/drink")
    public String adminDrink(){
        return "drink/index";
    }
    @GetMapping("/drink/addform")
    public String addDrink(){
        return "drink/add";
    }
    @GetMapping("/drink/updateform")
    public ModelAndView updatafrom(@RequestParam Integer id){
        ModelAndView mv=new ModelAndView("drink/edit");
        Drink drink=iDrinkService.getDrinkByID(id);
        mv.addObject("data",drink);
        return mv;
    }

    @GetMapping("/menu/student")
    public String adminStudent(){
        return "student/index";
    }
    @GetMapping("/student/addfrom")
    public String addStudent(){
        return "student/add";
    }
    @GetMapping("/student/updateform")
    public ModelAndView upstudentdatafrom(@RequestParam Integer id){
        ModelAndView mv=new ModelAndView("student/edit");
        Student build = Student.builder().id(13L)
                .name("赵六")
                .major("移动应用开发")
                .build();
        mv.addObject("data",build);
        return mv;
    }
}
